<?php
class LuminousGrammarJavaScript extends LuminousGrammar
{
  public $keywords =  array("break", "c(ase|atch|omment|ontinue)", 
    "d(efault|elete|o)", "e(lse|xport)",
    "f(or|unction)", "i(f|mport|n)",   "label", "return",  "switch",  "try",  
    "void", "w(hile|ith)");    
  
  public $functions = array('\$', 'encodeURI(?:Component)?', 
    'decodeURI(?:Component)?', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 
    'eval', 'alert', 'confirm', 'prompt', 'Array', 'Boolean', 'Date', 'Error', 
    'EvalError', 'Number', 'Object', 'RangeError', 'ReferenceError', 'RegExp', 
    'String', 'SyntaxError', 'TypeError', 'URIError');
  
  public $types = array('this', 'var', 'Infinity', 'Math', 'NaN', 'true', 
    'false', 'undefined', 'null', 'String', 'Date', 'Array', 'Object', 'Image', 
    'Option');
  
  public $oo_separators = array('\.');

  public function __construct()
  {
    
    $this->SetInfoAuthor( 
    array('name'=>'Mark Watkinson', 'email'=>'markwatkinson@gmail.com',
    'website'=>'http://www.asgaard.co.uk'));
    $this->SetInfoLanguage('js');
    $this->SetInfoVersion('0.4.0');    
    
    $this->operators = array_merge($this->operators,
    array('\?', '\:', '(?<![a-zA-Z0-9_])delete(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])get(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])in(stanceof)?(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])let(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])new(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])set(?![a-zA-Z0-9_])',
    '(?<![a-zA-Z0-9_])typeof(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])void(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])yield(?![a-zA-Z0-9_])'));
      
    
    $this->delimited_types = array(
      luminous_generic_doc_comment('/**', '*/'),
      luminous_generic_doc_comment('/*!', '*/'),
      luminous_generic_doc_comment('//!', "\n"),
      luminous_generic_doc_comment('///', "\n"),
      
      luminous_generic_comment('/*', '*/'),                               
      new LuminousDelimiterRule(0, 'COMMENT', LUMINOUS_STOP_AT_END, '//', "\n"),
      luminous_generic_string('"', '"'),
      luminous_generic_string("'", "'"),
      luminous_generic_regex('igm')
      
      // I can't decide which is faster.
      
// //       new LuminousDelimiterRule("REGEX", LUMINOUS_REGEX,
// //         '/
// //           (?<=([\(\[,=:;\?!]))
// //           [\s]* 
// //           \/[^\/\*]
// //           /x', '/\/[igm]*/')
//       
//       new LuminousDelimiterRule("REGEX", LUMINOUS_REGEX|LUMINOUS_COMPLETE, 
//         '/
//         (?<=([\(\[,=:;\?!\|\&]))
//         [\s]* 
//         \/(?![\/\*])
//         (?:.*?[^\\\])*?
//         (?:\\\\\\\\)*\/
//         [igm]*/x',
//         null,
//         'luminous_type_callback_generic_string'
//       )
    );


    $this->SetSimpleTypeRules();
    $this->simple_types[] = luminous_generic_constant();
    
  }
  
  
}


class LuminousGrammarJavaScriptEmbedded extends LuminousGrammarJavaScript
{

  function __construct()
  {    
    $this->ignore_outside = array(
      new LuminousBoundaryRule(LUMINOUS_REGEX|LUMINOUS_EXCLUDE,
      "/(?:&lt;script.*?&gt;)/si", "/(?:&lt;\/?script&gt;)/si")
      );    
    $this->child_grammar = new LuminousGrammarCSSEmbedded();
    
    parent::__construct();
    $this->SetInfoAuthor( 
    array('name'=>'Mark Watkinson', 'email'=>'markwatkinson@gmail.com',
    'website'=>'http://www.asgaard.co.uk'));
    $this->SetInfoVersion('0.4.0');          
    
  }
}